package metalink.admin;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;

public class IncomingEvents extends ActionSupport {
	ArrayList<EventDetailsVo> events_list = new ArrayList<EventDetailsVo>();
	public ArrayList<EventDetailsVo> getEvents_list() {
		return events_list;
	}

	public void setEvents_list(ArrayList<EventDetailsVo> events_list) {
		this.events_list = events_list;
	}

	public ArrayList<EventDetailsVo> getComing() {
		return coming;
	}

	public void setComing(ArrayList<EventDetailsVo> coming) {
		this.coming = coming;
	}

	public ArrayList<EventDetailsVo> getNotcoming() {
		return notcoming;
	}

	public void setNotcoming(ArrayList<EventDetailsVo> notcoming) {
		this.notcoming = notcoming;
	}

	public ArrayList<EventDetailsVo> getMaybe() {
		return maybe;
	}

	public void setMaybe(ArrayList<EventDetailsVo> maybe) {
		this.maybe = maybe;
	}

	ArrayList<EventDetailsVo> coming = new ArrayList<EventDetailsVo>();
	ArrayList<EventDetailsVo> notcoming = new ArrayList<EventDetailsVo>();
	ArrayList<EventDetailsVo> maybe = new ArrayList<EventDetailsVo>();

	public String execute() 
	{
		try {
			HttpSession session = ServletActionContext.getRequest()
					.getSession();
			String username = session.getAttribute("username").toString();
			Connect c = new Connect();
			ResultSet rs = c
					.getResult("select * from event_details ed,event_participation ep where ed.event_id=ep.event_id and ep.participant_id='"
							+ username
							+ "' and ep.coming=0 and ep.notcoming=0 and ep.maybe=0 order by event_date desc");
			while (rs.next()) 
			{
				EventDetailsVo single_object = new EventDetailsVo();
				single_object.setEvent_id(rs.getInt("event_id"));
				single_object.setEvent_name(rs.getString("event_name"));
				single_object.setEvent_description(rs
						.getString("event_description"));
				single_object.setEvent_location(rs.getString("event_location"));
				single_object.setEvent_date(rs.getDate("event_date"));
				single_object.setEvent_time(rs.getTime("event_time"));
				single_object.setEvent_creator_id(rs
						.getString("event_creator_id"));
				events_list.add(single_object);
			}
			rs = c.getResult("select * from event_details ed,event_participation ep where ed.event_id=ep.event_id and ep.coming=1 order by event_date desc");
			while (rs.next())
			{
				EventDetailsVo single_object = new EventDetailsVo();
				single_object.setEvent_name(rs.getString("event_name"));
				single_object.setEvent_description(rs
						.getString("event_description"));
				single_object.setEvent_location(rs.getString("event_location"));
				single_object.setEvent_date(rs.getDate("event_date"));
				single_object.setEvent_time(rs.getTime("event_time"));
				single_object.setEvent_creator_id(rs
						.getString("event_creator_id"));
				single_object.setStatus("Coming");
				coming.add(single_object);
			}
			rs = c.getResult("select * from event_details ed,event_participation ep where ed.event_id=ep.event_id and ep.notcoming=1 order by event_date desc");
			while (rs.next())
			{
				EventDetailsVo single_object = new EventDetailsVo();
				single_object.setEvent_name(rs.getString("event_name"));
				single_object.setEvent_description(rs
						.getString("event_description"));
				single_object.setEvent_location(rs.getString("event_location"));
				single_object.setEvent_date(rs.getDate("event_date"));
				single_object.setEvent_time(rs.getTime("event_time"));
				single_object.setEvent_creator_id(rs
						.getString("event_creator_id"));
				single_object.setStatus("Not Coming");
				notcoming.add(single_object);
			}
			rs = c.getResult("select * from event_details ed,event_participation ep where ed.event_id=ep.event_id and ep.maybe=1 order by event_date desc ");
			while (rs.next()) 
			{
				EventDetailsVo single_object = new EventDetailsVo();
				single_object.setEvent_name(rs.getString("event_name"));
				single_object.setEvent_description(rs
						.getString("event_description"));
				single_object.setEvent_location(rs.getString("event_location"));
				single_object.setEvent_date(rs.getDate("event_date"));
				single_object.setEvent_time(rs.getTime("event_time"));
				single_object.setEvent_creator_id(rs
						.getString("event_creator_id"));
				single_object.setStatus("Maybe");
				maybe.add(single_object);
			}
return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
}
